﻿Imports DotNetNuke.Entities.Modules
Public Class SiteLinksController
    Public Function GetRootPages() As Classes.SitePages
        Try
            Dim SiteDatabase As New Data.SqlDataProvider
            Dim ListOfPages As New Classes.SitePages
            Dim RetrievedData As IDataReader
            RetrievedData = SiteDatabase.GetRootPages
            SiteDatabase = Nothing
            While RetrievedData.Read
                Dim CurrentSitePage As New Classes.SitePage
                CurrentSitePage.TabID = CType(RetrievedData.GetValue(0), Integer)
                If Not IsDBNull(RetrievedData.GetValue(1)) Then
                    CurrentSitePage.ParentID = CType(RetrievedData.GetValue(1), Integer)
                End If
                CurrentSitePage.Title = CType(RetrievedData.GetValue(2), String)
                CurrentSitePage.TabName = CType(RetrievedData.GetValue(3), String)
                CurrentSitePage.TabOrder = CType(RetrievedData.GetValue(4), Integer)
                If Not IsDBNull(RetrievedData.GetValue(5)) Then
                    CurrentSitePage.URL = CType(RetrievedData.GetValue(5), String)
                End If
                CurrentSitePage.Level = CType(RetrievedData.GetValue(6), Integer)
                CurrentSitePage.TabPath = CType(RetrievedData.GetValue(7), String)
                ListOfPages.Add(CurrentSitePage)
            End While
            RetrievedData = Nothing
            Return ListOfPages
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Function GetParentPages(ByRef TabID As Integer) As Classes.SitePages
        Try
            Dim SiteDatabase As New Data.SqlDataProvider
            Dim ListOfPages As New Classes.SitePages
            Dim RetrievedData As IDataReader
            RetrievedData = SiteDatabase.GetParentPages(TabID)
            SiteDatabase = Nothing
            While RetrievedData.Read
                Dim CurrentSitePage As New Classes.SitePage
                CurrentSitePage.TabID = CType(RetrievedData.GetValue(0), Integer)
                If Not IsDBNull(RetrievedData.GetValue(1)) Then
                    CurrentSitePage.ParentID = CType(RetrievedData.GetValue(1), Integer)
                End If
                CurrentSitePage.Title = CType(RetrievedData.GetValue(2), String)
                CurrentSitePage.TabName = CType(RetrievedData.GetValue(3), String)
                CurrentSitePage.TabOrder = CType(RetrievedData.GetValue(4), Integer)
                If Not IsDBNull(RetrievedData.GetValue(5)) Then
                    CurrentSitePage.URL = CType(RetrievedData.GetValue(5), String)
                End If
                CurrentSitePage.Level = CType(RetrievedData.GetValue(6), Integer)
                CurrentSitePage.TabPath = CType(RetrievedData.GetValue(7), String)
                ListOfPages.Add(CurrentSitePage)
            End While
            RetrievedData = Nothing
            Return ListOfPages
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Function GetChildPages(ByRef TabID As Integer) As Classes.SitePages
        Try
            Dim SiteDatabase As New Data.SqlDataProvider
            Dim ListOfPages As New Classes.SitePages
            Dim RetrievedData As IDataReader
            RetrievedData = SiteDatabase.GetChildPages(TabID)
            SiteDatabase = Nothing
            While RetrievedData.Read
                Dim CurrentSitePage As New Classes.SitePage
                CurrentSitePage.TabID = CType(RetrievedData.GetValue(0), Integer)
                If Not IsDBNull(RetrievedData.GetValue(1)) Then
                    CurrentSitePage.ParentID = CType(RetrievedData.GetValue(1), Integer)
                End If
                CurrentSitePage.Title = CType(RetrievedData.GetValue(2), String)
                CurrentSitePage.TabName = CType(RetrievedData.GetValue(3), String)
                CurrentSitePage.TabOrder = CType(RetrievedData.GetValue(4), Integer)
                If Not IsDBNull(RetrievedData.GetValue(5)) Then
                    CurrentSitePage.URL = CType(RetrievedData.GetValue(5), String)
                End If
                CurrentSitePage.Level = CType(RetrievedData.GetValue(6), Integer)
                CurrentSitePage.TabPath = CType(RetrievedData.GetValue(7), String)
                ListOfPages.Add(CurrentSitePage)
            End While
            RetrievedData = Nothing
            Return ListOfPages
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Function GetSameLevelPages(ByRef TabID As Integer) As Classes.SitePages
        Try
            Dim SiteDatabase As New Data.SqlDataProvider
            Dim ListOfPages As New Classes.SitePages
            Dim RetrievedData As IDataReader
            RetrievedData = SiteDatabase.GetSameLevelPages(TabID)
            SiteDatabase = Nothing
            While RetrievedData.Read
                Dim CurrentSitePage As New Classes.SitePage
                CurrentSitePage.TabID = CType(RetrievedData.GetValue(0), Integer)
                If Not IsDBNull(RetrievedData.GetValue(1)) Then
                    CurrentSitePage.ParentID = CType(RetrievedData.GetValue(1), Integer)
                End If
                CurrentSitePage.Title = CType(RetrievedData.GetValue(2), String)
                CurrentSitePage.TabName = CType(RetrievedData.GetValue(3), String)
                CurrentSitePage.TabOrder = CType(RetrievedData.GetValue(4), Integer)
                If Not IsDBNull(RetrievedData.GetValue(5)) Then
                    CurrentSitePage.URL = CType(RetrievedData.GetValue(5), String)
                End If
                CurrentSitePage.Level = CType(RetrievedData.GetValue(6), Integer)
                CurrentSitePage.TabPath = CType(RetrievedData.GetValue(7), String)
                ListOfPages.Add(CurrentSitePage)
            End While
            RetrievedData = Nothing
            Return ListOfPages
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Function GetAllPages() As Classes.SitePages
        Try
            Dim SiteDatabase As New Data.SqlDataProvider
            Dim ListOfPages As New Classes.SitePages
            Dim RetrievedData As IDataReader
            RetrievedData = SiteDatabase.GetAllPages
            SiteDatabase = Nothing
            While RetrievedData.Read
                Dim CurrentSitePage As New Classes.SitePage
                CurrentSitePage.TabID = CType(RetrievedData.GetValue(0), Integer)
                If Not IsDBNull(RetrievedData.GetValue(1)) Then
                    CurrentSitePage.ParentID = CType(RetrievedData.GetValue(1), Integer)
                End If
                CurrentSitePage.Title = CType(RetrievedData.GetValue(2), String)
                CurrentSitePage.TabName = CType(RetrievedData.GetValue(3), String)
                CurrentSitePage.TabOrder = CType(RetrievedData.GetValue(4), Integer)
                If Not IsDBNull(RetrievedData.GetValue(5)) Then
                    CurrentSitePage.URL = CType(RetrievedData.GetValue(5), String)
                End If
                CurrentSitePage.Level = CType(RetrievedData.GetValue(6), Integer)
                CurrentSitePage.TabPath = CType(RetrievedData.GetValue(7), String)
                ListOfPages.Add(CurrentSitePage)
            End While
            RetrievedData = Nothing
            Return ListOfPages
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Function GetSinglePage(ByRef TabID As Integer) As Classes.SitePage
        Try
            Dim SiteDatabase As New Data.SqlDataProvider
            Dim CurrentSitePage As New Classes.SitePage
            Dim RetrievedData As IDataReader
            RetrievedData = SiteDatabase.GetSinglePage(TabID)
            SiteDatabase = Nothing
            RetrievedData.Read()
            CurrentSitePage.TabID = CType(RetrievedData.GetValue(0), Integer)
            If Not IsDBNull(RetrievedData.GetValue(1)) Then
                CurrentSitePage.ParentID = CType(RetrievedData.GetValue(1), Integer)
            End If
            CurrentSitePage.Title = CType(RetrievedData.GetValue(2), String)
            CurrentSitePage.TabName = CType(RetrievedData.GetValue(3), String)
            CurrentSitePage.TabOrder = CType(RetrievedData.GetValue(4), Integer)
            If Not IsDBNull(RetrievedData.GetValue(5)) Then
                CurrentSitePage.URL = CType(RetrievedData.GetValue(5), String)
            End If
            CurrentSitePage.Level = CType(RetrievedData.GetValue(6), Integer)
            CurrentSitePage.TabPath = CType(RetrievedData.GetValue(7), String)
            RetrievedData = Nothing
            Return CurrentSitePage
        Catch ex As Exception
            Throw ex
        End Try
    End Function

End Class
